$(document).ready(function () {
    $('.a-del').click(function () {
        var id = $(this).attr('id');
        var del_url = $(this).attr('del-url');
        console.log(del_url, id);
        swal({
                title: '是否删除',
                text: `你将无法恢复该条数据!`,
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                cancelButtonText: "取消",
                confirmButtonText: "是的，删除",
                closeOnConfirm: false
            },
            function () {
                $.ajax({
                    url: `${del_url}`,
                    type: 'post',
                    data: {
                        pk: id,
                        csrfmiddlewaretoken: $('input[name="csrfmiddlewaretoken"]').val(),
                    },
                    success: function (data) {
                        if (data == '200') {
                            location.reload();
                        }
                    }
                });
                // {#swal("删除", "删除成功", "success");#}
            });
    });


    $('.a-reset').click(function () {
        var id = $(this).attr('reset-id');
        var reset_url = $(this).attr('reset-url');
        console.log(reset_url, id);
        swal({
                title: "是否重置密码！",
                text: "将重置用户密码",
                type: "success",
                showCancelButton: true,
                confirmButtonColor: "#1BB394",
                cancelButtonText: "取消",
                confirmButtonText: "是的，重置！",
                closeOnConfirm: false
            },
            function () {
                $.ajax({
                    url: `${reset_url}`,
                    type: 'post',
                    data: {
                        pk: id,
                        csrfmiddlewaretoken: $('input[name="csrfmiddlewaretoken"]').val(),
                    },
                    success: function (data) {
                        console.log(data);
                        if (data == '200') {
                            location.reload();
                        }else {
                            alert('403!!!');
                        }
                    }
                });
                // {#swal("删除", "删除成功", "success");#}
            });
    });

});